package cc.wd.demo.blockchain.model;

import cc.wd.demo.blockchain.utils.SecureUtil;

import java.security.PublicKey;

/**
 * @author wudi
 * @date 2018/8/29
 */
public class TransactionOutput {
    public String id;
    public PublicKey receiver; //持有者的公钥
    public float value; //持有者的金额
    public String parentTransactionId; //交易编号

    //构造器
    public TransactionOutput(PublicKey receiver, float value, String parentTransactionId) {
        this.receiver = receiver;
        this.value = value;
        this.parentTransactionId = parentTransactionId;
        this.id = SecureUtil.Sha256(SecureUtil.getStringFromKey(receiver) + Float.toString(value) + parentTransactionId);
    }

    //用来验证是否属于你
    public boolean isMine(PublicKey publicKey) {
        return (publicKey == receiver);
    }
}
